function [sudo_final, nb_iteration, energie_finale] = Recuit(sudoku)

% Fonction permettant de vider une matrice plein pour en faire un sudoku avec un minimum de de cases remplies et possedant une unique solution grace a l'algorithme du recuit simule

sudoku_depart = sudoku;

sudo = sudoku;

temperature = 100;
nb_iter = 2500;
amortissement = 0.997;
nb_iteration = 0;
energie = 81;
energieMin = energie;
iterMin = 0;
sudoku_min = sudoku;

p = 0;

while (p<nb_iter && energie > 17)
	delta = -1;
	if (energie <81 && rand() < 0.5)
		delta = 1;
	end
	if (delta < 0)		
		i = round(rand*8 +1);
		j = round(rand*8 +1);
		while (sudo(i, j) == 0)
			i = round(rand*8 +1);
			j = round(rand*8 +1);
		end
		k = sudo(i, j);
		sudo(i, j) = 0;
		nb_sol = sudoku_contrainte_all(sudo);
		if (nb_sol ~= 1)
			sudo(i, j) = k;
		else
			energie = energie + delta;
			if (energie < energieMin)
				energieMin = energie;
				iterMin = p;
				sudoku_min = sudo;
			end
		end
	else
		accept = exp(-delta/temperature);
		random = rand();
		if (random < accept)
			i = round(rand*8 +1);
			j = round(rand*8 +1);
			while (sudo(i, j) ~= 0)
				i = round(rand*8 +1);
				j = round(rand*8 +1);
			end
			k1 = sudoku_depart(i, j);
			sudo(i, j) = k1;
			energie = energie + delta;
		end
	end
	p = p + 1;
	temperature = temperature * amortissement;
end
sudo_final = sudoku_min;
energie_finale = energieMin;
nb_iteration = iterMin;
return;
